package org.Vancl.Dao.ImpI;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.Vancl.Dao.NavigationDao;
import org.Vancl.entity.Navigation;
import org.Vancl.utils.BaseDao;

public class NavigationDaoImpI extends BaseDao implements NavigationDao {

	
	public List<Navigation> getAll() {
		String sql="SELECT * FROM Navigation";
		ResultSet rs=super.executeQuery(sql);
		List<Navigation> Navlist=new ArrayList();
		try {
			while(rs.next()) {
				Navigation nav=new Navigation();
				nav.setN_id(rs.getInt("n_id"));
				nav.setN_name(rs.getString("n_name"));
				Navlist.add(nav);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return Navlist;
	}

	@Override
	public int add(Navigation navigation) {
		String sql="INSERT INTO Navigation(n_name) VALUES (?)";
		return super.executeUpdate(sql, navigation.getN_name());
	}

	@Override
	public Navigation getid(int id) {
		String sql="SELECT * FROM Navigation where n_id=?";
		ResultSet rs=super.executeQuery(sql,id);
		Navigation nav=null;
		try {
			while(rs.next()) {
				nav=new Navigation();
				nav.setN_id(rs.getInt("n_id"));
				nav.setN_name(rs.getString("n_name"));
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return nav;
	}

	@Override
	public int update(Navigation nav) {
		String sql="update Navigation set n_name=? where n_id=?";
		return super.executeUpdate(sql, nav.getN_name(),nav.getN_id());
	}

}
